﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using Windows8Accelerator.Core.Xaml.Helpers;

namespace Windows8Accelerator.Core.Xaml.Controls
{
    public class GroupHeaderContentControl : Button
    {
        private InternalGridView _InternalGridView;
        
        public GroupHeaderContentControl()
        {
            DefaultStyleKey = typeof(GroupHeaderContentControl);
            Click += GroupHeaderContentControl_Click;
        }

        void GroupHeaderContentControl_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (_InternalGridView != null)
            {
                if (_InternalGridView.GroupHeaderClickCommand != null)
                { 
                    _InternalGridView.GroupHeaderClickCommand.Execute(((GroupItem)this.Content).Item);
                }
            }
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _InternalGridView = ControlHelper.GetParentOf<InternalGridView>(this);
        }
    }
}
